package com.fansl.koala.quickdev.common.enums;

import com.fansl.koala.quickdev.common.exception.BizException;
import com.fansl.koala.quickdev.common.exception.EnumNotfoundException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author fansl
 * @Description: 状态枚举类
 * @date 2020/3/20 18:20
 */
@Getter
@AllArgsConstructor
public enum  StatusEnum {
    /**
     * 正常
     */
    NORMAL("1","正常"),
    /**
     * 禁用
     */
    DISABLE("2","禁用"),
    ;
    private final String code;
    private final String message;

    /**
     * 根据code获取枚举值，未找到抛出异常
     * @param code 代码
     * @return 枚举成员
     */
    public static StatusEnum findByCode(String code) {
        return Arrays.stream(StatusEnum.values())
                .filter(enumMember -> enumMember.code.equals(code))
                .findFirst()
                .orElseThrow(EnumNotfoundException::new);
    }
}
